﻿Imports System.Data.SQLite
Module modSQLiteWrapper
    Public Function ExecuteSQ(ByVal sq As String) As Integer
        Dim SQLconnect As New SQLite.SQLiteConnection()
        Dim SQLcommand As SQLiteCommand
        SQLconnect.ConnectionString = "Data Source=" & g_sDbName & ";"
        SQLconnect.Open()
        If SQLconnect.State = ConnectionState.Open Then
            SQLcommand = SQLconnect.CreateCommand
            'Checks if image needs to be updated
            ''If btn_update_select.Text = "Select Image File" Then
            SQLcommand.CommandText = sq
            ''Else
            ''@image CANNOT be in single quotes
            ''SQLcommand.CommandText = "UPDATE " & cmb_update_tables.SelectedItem & " SET title = '" & txt_update_title.Text.Replace("'", "''") & "', description =  '" & txt_update_description.Text.Replace("'", "\'") & "', image = @image WHERE id = '" & (cmb_update_records.SelectedIndex + 1) & "'"
            ''Sets the meaning of @image.
            ''SQLcommand.Parameters.Add(ImageToBlob("@image", btn_update_select.Text))
            ''End If
            'Runs Query
            SQLcommand.ExecuteNonQuery()
            SQLcommand.Dispose()
        End If
        SQLconnect.Close()
    End Function
End Module
